package com.sec.foodit;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;

public class FavoriteActivity extends Activity {

	private ActivityManager am = ActivityManager.getInstance();
	private ListView list;
	LazyAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_favorite);
		
		am.addActivity(this);
		
		getActionBar().setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
		
		list=(ListView)findViewById(R.id.list);
		adapter=new LazyAdapter(this, DataManager.getInstance().getfList()); 
		list.setAdapter(adapter); 
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int menuId = item.getItemId();
		 
		//이벤트 할당
		switch(menuId) {
			case R.id.menu_nearby:
				startActivity(new Intent("com.sec.foodit.HomeScreenActivity"));
				break;
			case R.id.menu_myboard:
				startActivity(new Intent("com.sec.foodit.MyBoardActivity"));
				break;
			case R.id.menu_favorite:
				startActivity(new Intent("com.sec.foodit.FavoriteActivity"));
				break;
			case R.id.menu_settings:
				startActivity(new Intent("com.sec.foodit.SettingsActivity"));
				break;
		}
		overridePendingTransition(0, 0);
		finish();
		return true;
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater(); 
		menuInflater.inflate(R.menu.activity_tabs, menu); 
		return true; 
	}


	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			AlertDialog dialog = null;
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle("Foodit을 종료하시겠습니까?");
			//builder.setMessage("Foodit을 종료하시겠습니까?");
			builder.setPositiveButton("종료", new DialogInterface.OnClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which) {
					am.finishAllActivity();
				}
			});
			builder.setNegativeButton("취소", null);
			builder.show();

			return false;
		}
		return super.onKeyDown(keyCode, event);
	}


	@Override
	protected void onDestroy() {
		super.onDestroy();
		am.removeActivity(this);
	}
	
	

}
